<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./node_modules/vue/dist/vue.js"></script>
</head>
<body>
    <div id="root">
        <child content="dell"></child>
        <child content="Lee"></child>
    </div>

<script>
//发布订阅模式(总线模式/bus/观察者模式)
Vue.prototype.bus = new Vue()
    Vue.component(
        'child',
        {
            data(){
                return{
                    selfContent:this.content
                }
            },
            props:{
                content:String
            },
            template:"<div @click='handleclick' >{{selfContent}}</div>",
            methods:{
                handleclick(){
                    this.bus.$emit('change',this.selfContent)
                }
            },
            mounted() {
                this.bus.$on('change',function(msg){
                    var _that = this
                    _that.selfContent = msg
                })
            },
        }
    )

    var vm = new Vue ({
        el:"#root",

    })
</script>

</body>
</html>